package com.css.prompt.controller;

import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.css.prompt.model.MyFolder;
import com.css.prompt.service.MyFolderService;

@RestController
@RequestMapping("/prompt/my-folder")
public class MyFolderController {

    private final MyFolderService myFolderService;

    public MyFolderController(MyFolderService myFolderService) {
        this.myFolderService = myFolderService;
    }

    @GetMapping
    public List<MyFolder> getAllMyFolders() {
        return myFolderService.getAllMyFolders();
    }

    @GetMapping("/{id}")
    public MyFolder getMyFolderById(@PathVariable Long id) {
        return myFolderService.getMyFolderById(id).orElseThrow(() -> new RuntimeException("文件夹 not found"));
    }

    @PostMapping
    public MyFolder createMyFolder(@RequestBody MyFolder myFolder) {
        return myFolderService.createMyFolder(myFolder);
    }

    @PutMapping("/{id}")
    public MyFolder updateMyFolder(@PathVariable Long id, @RequestBody MyFolder myFolder) {
        return myFolderService.updateMyFolder(id, myFolder);
    }

    @DeleteMapping("/{id}")
    public void deleteMyFolder(@PathVariable Long id) {
    	myFolderService.deleteMyFolder(id);
    }
    
}
